home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / terms / kermit / a / apxa2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-15  |  19.0 KB  |  747 lines

  1. #!/bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #!/bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create the files:
  6. #    as6502.1
  7. #    assm.d1
  8. #    assm.d2
  9. #    assm0.c
  10. #    assm1.c
  11. # This archive created: Tue Apr  2 14:21:10 1985
  12. # By:    James Van Ornum (AT&T-Bell Laboratories)
  13. export PATH; PATH=/bin:$PATH
  14. if test -f 'as6502.1'
  15. then
  16.     echo shar: over-writing existing file "'as6502.1'"
  17. fi
  18. cat << \SHAR_EOF > 'as6502.1'
  19. .TH AS6502 1 11/5/84 
  20. .SH NAME
  21. as6502 \- assembler for MOS Technology 650X microprocessors
  22. .SH SYNOPSIS
  23. .B as6502
  24. [ option ] file ...
  25. .SH DESCRIPTION
  26. .I As6502
  27. assembles the named files and produces
  28. a listing on the standard output.
  29. Available options are:
  30. .TP 4
  31. .B \-i
  32. ignore .nlst pseudo ops in the source file.
  33. .TP
  34. .B \-l
  35. produce only an error listing on the standard output.
  36. .TP
  37. .B \-n
  38. print address in normal <high byte><low byte> format,
  39. rather than split <low byte>:<high byte> format.
  40. .TP
  41. .B \-o
  42. generate the ASCII object file
  43. .B "6502.out."
  44. The per-line format of that file is:
  45. .br
  46.     ;<address low byte><address high byte><data>...
  47. .TP
  48. .B \-s
  49. print symbol table at the end of the assembly listing.
  50. .TP
  51. Symbol conventions:
  52. .br
  53. .tr ~|
  54. Up to 19 alphanumeric (a-z ~ A-Z ~ 0-9 ~ . ~ _) characters,
  55. .tr ~~
  56. with initial character non-numeric.
  57. .sp
  58. Asterisk (*) is symbolic name of the location counter.
  59. .TP
  60. .B \-v
  61. print version of assembler.
  62. .TP
  63. Op code mnemonics (upper and/or lower case):
  64. .br
  65. ADC   BIT   BVS   CPX   INC   LDX   PHP   RTI   SEI  TAY
  66. .br
  67. AND   BMI   CLC   CPY   INX   LDY   PLA   RTS   STA  TSX
  68. .br
  69. ASL   BNE   CLD   DEC   INY   LSR   PLP   SBC   STX  TXA
  70. .br
  71. BCC   BPL   CLI   DEX   JMP   NOP   ROL   SEC   STY  TXS
  72. .br
  73. BCS   BRK   CLV   DEY   JSR   ORA   ROR   SED   TAX  TYA
  74. .br
  75. BEQ   BVC   CMP   EOR   LDA   PHA
  76. .TP
  77. Pseudo op mnemonics:
  78. .br
  79. =      equate label to operand value.
  80. .br
  81. *=     equate location counter to operand value.
  82. .br
  83.  .WORD  assign 16 bit operand value to next 2 locations.
  84. .br
  85.  .DBYT  assign 16 bit value to next 2 locations, reverse.
  86. .br
  87.  .BYTE  assign 8 bit operand value to next location.
  88. .br
  89.  .NLST  turn listing mode off.
  90. .br
  91.  .LIST  turn listing mode on.
  92. .TP
  93. Constant types:
  94. .br
  95. %       binary number prefix.
  96. .br
  97. @ or 0  octal number prefix.
  98. .br
  99. $       hexadecimal number prefix.
  100. .br
  101.  '       ASCII character prefix.
  102. .br
  103.  "       ASCII character string prefix and suffix.
  104. .br
  105. default (leading digit 1 through 9)  decimal number.
  106. .TP
  107. Operand field operators:
  108. .br
  109. +     addition               ^     logical exclusive OR
  110. .br
  111. -     subtraction            ~     logical 1's complement
  112. .br
  113. /     integer division       $     logical AND
  114. .br
  115. .tr ||
  116. *     multiplication         |     logical OR
  117. .br
  118. %     modulo                 <     low byte
  119. .br
  120.                              >     high byte
  121. .SH FILES
  122. .PD 0
  123. .TP
  124. /BIN/as6502   the assembler
  125. .TP
  126. 6502.out      object (with -o option)
  127. .SH "SEE ALSO"
  128. .TP
  129. J. H. Van Ornum, "as6502 User Notes"
  130. .SH DIAGNOSTICS
  131. .in 0
  132. File handling diagnostics:
  133. .in 15
  134. .ti 5
  135. Invalid argument count - as6502 invoked without a source file or
  136. with too many source files.
  137. .ti 5
  138. Open error for file <name> - as6502 cannot open source file.
  139. .ti 5
  140. Create error (6502.out) - as6502 cannot create object file.
  141. .ti 5
  142. Close error - as6502 cannot close the source file.
  143. .ti 5
  144. Close error (6502.out) - as6502 cannot close object file.
  145. .in 0
  146. Assembly error diagnostics:
  147. .in 15
  148. .ti 5
  149. Symbol table full - symbol table overflowed allotted space.
  150. Number of symbols is a function of symbol sizes.
  151. .ti 5
  152. Label multiply defined - symbol defined more than once.
  153. .ti 5
  154. Sync error - the pass 2 value of symbol in the label field is different
  155. than the pass 1 value.
  156. .ti 5
  157. Invalid operation code - op code mnemonic is invalid.
  158. .ti 5
  159. Operand field missing - the op code mnemonic requires an operand, and none was
  160. found.
  161. .ti 5
  162. Invalid operand field - operand field contains an operator which is not
  163. recognized by as6502.
  164. .ti 5
  165. Invalid branch address - branch instruction to a location which is out of range.
  166. .ti 5
  167. Invalid addressing mode - tried to use an addressing mode which is not
  168. available to the operation code.
  169. .ti 5
  170. Operand field size error - operand is larger than hex FF.
  171. .ti 5
  172. Undefined symbol in operand field - a symbol in the operand field never
  173. appeared in the label field.
  174. .SH BUGS
  175. SHAR_EOF
  176. if test -f 'assm.d1'
  177. then
  178.     echo shar: over-writing existing file "'assm.d1'"
  179. fi
  180. cat << \SHAR_EOF > 'assm.d1'
  181. #define LAST_CH_POS    132
  182. #define SFIELD    23
  183. #define STABSZ    16000
  184. #define SBOLSZ    20
  185.  
  186. /*
  187.  * symbol flags
  188.  */
  189. #define DEFZRO    2    /* defined - page zero address    */
  190. #define MDEF    3    /* multiply defined        */
  191. #define UNDEF    1    /* undefined - may be zero page */
  192. #define DEFABS    4    /* defined - two byte address    */
  193. #define UNDEFAB 5    /* undefined - two byte address */
  194.  
  195. /*
  196.  * operation code flags
  197.  */
  198. #define PSEUDO    0x6000
  199. #define CLASS1    0x2000
  200. #define CLASS2    0x4000
  201. #define IMM1    0x1000        /* opval + 0x00    2 byte    */
  202. #define IMM2    0x0800        /* opval + 0x08    2 byte    */
  203. #define ABS    0x0400        /* opval + 0x0C    3 byte    */
  204. #define ZER    0x0200        /* opval + 0x04    2 byte    */
  205. #define INDX    0x0100        /* opval + 0x00    2 byte    */
  206. #define ABSY2    0x0080        /* opval + 0x1C    3 byte    */
  207. #define INDY    0x0040        /* opval + 0x10    2 byte    */
  208. #define ZERX    0x0020        /* opval + 0x14    2 byte    */
  209. #define ABSX    0x0010        /* opval + 0x1C    3 byte    */
  210. #define ABSY    0x0008        /* opval + 0x18    3 byte    */
  211. #define ACC    0x0004        /* opval + 0x08    1 byte    */
  212. #define IND    0x0002        /* opval + 0x2C    3 byte    */
  213. #define ZERY    0x0001        /* opval + 0x14    2 byte    */
  214.  
  215. /*
  216.  * pass flags
  217.  */
  218. #define FIRST_PASS    0
  219. #define LAST_PASS    1
  220. #define DONE        2
  221. SHAR_EOF
  222. if test -f 'assm.d2'
  223. then
  224.     echo shar: over-writing existing file "'assm.d2'"
  225. fi
  226. cat << \SHAR_EOF > 'assm.d2'
  227. extern    FILE    *optr;
  228. extern    FILE    *iptr;
  229. extern    int    dflag;        /* debug flag */
  230. extern    int    errcnt;        /* error counter */
  231. extern    int    hash_tbl[];    /* pointers to starting links in symtab */
  232. extern    char    hex[];        /* hexadecimal character buffer */
  233. extern    int    iflag;        /* ignore .nlst flag */
  234. extern    int    lablptr;    /* label pointer into symbol table */
  235. extern    int    lflag;        /* disable listing flag */
  236. extern    int    loccnt;        /* location counter    */
  237. extern    int    nflag;        /* normal/split address mode */
  238. extern    int    nxt_free;    /* next free location in symtab */
  239. extern    int    objcnt;        /* object byte counter */
  240. extern    int    oflag;        /* object output flag */
  241. extern    int    opflg;        /* operation code flags */
  242. extern    int    opval;        /* operation code value */
  243. extern    int    pass;        /* pass counter        */
  244. extern    char    prlnbuf[];    /* print line buffer    */
  245. extern    int    sflag;        /* symbol table output flag */
  246. extern    int    slnum;        /* source line number counter */
  247. extern    char    symtab[];    /* symbol table        */
  248. extern    char    symbol[];    /* temporary symbol storage    */
  249. extern    int    udtype;        /* undefined symbol type    */
  250. extern    int    undef;        /* undefined symbol in expression flg  */
  251. extern    int    value;        /* operand field value */
  252. extern    char    zpref;        /* zero page reference flag    */
  253. extern  int    msb;        /* most significant bit for bytes    */
  254. SHAR_EOF
  255. if test -f 'assm0.c'
  256. then
  257.     echo shar: over-writing existing file "'assm0.c'"
  258. fi
  259. cat << \SHAR_EOF > 'assm0.c'
  260. #include "stdio.h"
  261. #include "assm.d1"
  262.  
  263. /*  Assembler for the MOS Technology 650X series of microprocessors
  264.  *  Written by J. H. Van Ornum (201) 949-1781
  265.  *        AT&T Bell Laboratories
  266.  *         Holmdel, NJ
  267.  */
  268.  
  269. FILE    *optr;
  270. FILE    *iptr;
  271. int    dflag;            /* debug flag */
  272. int    errcnt;            /* error counter */
  273. int    hash_tbl[128];        /* pointers to starting links in symtab */
  274. char    hex[5];            /* hexadecimal character buffer */
  275. int    iflag;            /* ignore .nlst flag */
  276. int    lablptr;        /* label pointer into symbol table */
  277. int    lflag;            /* disable listing flag */
  278. int    loccnt;            /* location counter    */
  279. int    nflag;            /* normal/split address mode */
  280. int    nxt_free;        /* next free location in symtab */
  281. int    objcnt;            /* object byte counter */
  282. int    oflag;            /* object output flag */
  283. int    opflg;            /* operation code flags */
  284. int    opval;            /* operation code value */
  285. int    pass;            /* pass counter        */
  286. char    prlnbuf[LAST_CH_POS+1]; /* print line buffer    */
  287. int    sflag;            /* symbol table output flag */
  288. int    slnum;            /* source line number counter */
  289. char    symtab[STABSZ];        /* symbol table        */
  290.                 /* struct sym_tab        */
  291.                 /* {    char    size;        */
  292.                 /*    char    chars[size];    */
  293.                 /*    char    flag;        */
  294.                 /*    int    value;        */
  295.                 /*    int    next_pointer    */
  296.                 /* }                */
  297. char    symbol[SBOLSZ];        /* temporary symbol storage    */
  298. int    udtype;            /* undefined symbol type    */
  299. int    undef;            /* undefined symbol in expression flg  */
  300. int    value;            /* operand field value */
  301. char    zpref;            /* zero page reference flag    */
  302. int    msb    = 0x80 ;        /* hibit for bytes */
  303.  
  304.  
  305. #define A    0x20)+('A'&0x1f))
  306. #define B    0x20)+('B'&0x1f))
  307. #define C    0x20)+('C'&0x1f))
  308. #define D    0x20)+('D'&0x1f))
  309. #define E    0x20)+('E'&0x1f))
  310. #define F    0x20)+('F'&0x1f))
  311. #define G    0x20)+('G'&0x1f))
  312. #define H    0x20)+('H'&0x1f))
  313. #define I    0x20)+('I'&0x1f))
  314. #define J    0x20)+('J'&0x1f))
  315. #define K    0x20)+('K'&0x1f))
  316. #define L    0x20)+('L'&0x1f))
  317. #define M    0x20)+('M'&0x1f))
  318. #define N    0x20)+('N'&0x1f))
  319. #define O    0x20)+('O'&0x1f))
  320. #define P    0x20)+('P'&0x1f))
  321. #define Q    0x20)+('Q'&0x1f))
  322. #define R    0x20)+('R'&0x1f))
  323. #define S    0x20)+('S'&0x1f))
  324. #define T    0x20)+('T'&0x1f))
  325. #define U    0x20)+('U'&0x1f))
  326. #define V    0x20)+('V'&0x1f))
  327. #define W    0x20)+('W'&0x1f))
  328. #define X    0x20)+('X'&0x1f))
  329. #define Y    0x20)+('Y'&0x1f))
  330. #define Z    0x20)+('Z'&0x1f))
  331.  
  332. #define OPSIZE    127
  333.  
  334. int    optab[]    =        /* nmemonic  operation code table    */
  335. {                /* '.' = 31, '*' = 30, '=' = 29        */
  336.     ((0*0x20)+(29)),PSEUDO,1,
  337.     ((0*0x20)+(29)),PSEUDO,1,
  338.     ((((0*D*S,PSEUDO,7,
  339.     ((((0*D*S,PSEUDO,7,
  340.     ((((0*D*W,PSEUDO,2,
  341.     ((((0*D*W,PSEUDO,2,
  342.     ((((0*0x20)+(30))*0x20)+(29)),PSEUDO,3,
  343.     ((((0*0x20)+(30))*0x20)+(29)),PSEUDO,3,
  344.     ((((((0*A*D*C,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x61,
  345.     ((((((0*A*D*C,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x61,
  346.     ((((((0*A*N*D,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x21,
  347.     ((((((0*A*N*D,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x21,
  348.     ((((((0*A*S*C,PSEUDO,8,
  349.     ((((((0*A*S*C,PSEUDO,8,
  350.     ((((((0*A*S*L,ABS|ZER|ZERX|ABSX|ACC,0x02,
  351.     ((((((0*A*S*L,ABS|ZER|ZERX|ABSX|ACC,0x02,
  352.     ((((((0*B*C*C,CLASS2,0x90,
  353.     ((((((0*B*C*C,CLASS2,0x90,
  354.     ((((((0*B*C*S,CLASS2,0xb0,
  355.     ((((((0*B*C*S,CLASS2,0xb0,
  356.     ((((((0*B*E*Q,CLASS2,0xf0,
  357.     ((((((0*B*E*Q,CLASS2,0xf0,
  358.     ((((((0*B*I*T,ABS|ZER,0x20,
  359.     ((((((0*B*I*T,ABS|ZER,0x20,
  360.     ((((((0*B*M*I,CLASS2,0x30,
  361.     ((((((0*B*M*I,CLASS2,0x30,
  362.     ((((((0*B*N*E,CLASS2,0xd0,
  363.     ((((((0*B*N*E,CLASS2,0xd0,
  364.     ((((((0*B*P*L,CLASS2,0x10,
  365.     ((((((0*B*P*L,CLASS2,0x10,
  366.     ((((((0*B*R*K,CLASS1,0x00,
  367.     ((((((0*B*R*K,CLASS1,0x00,
  368.     ((((((0*B*V*C,CLASS2,0x50,
  369.     ((((((0*B*V*C,CLASS2,0x50,
  370.     ((((((0*B*V*S,CLASS2,0x70,
  371.     ((((((0*B*V*S,CLASS2,0x70,
  372.     ((((((0*C*L*C,CLASS1,0x18,
  373.     ((((((0*C*L*C,CLASS1,0x18,
  374.     ((((((0*C*L*D,CLASS1,0xd8,
  375.     ((((((0*C*L*D,CLASS1,0xd8,
  376.     ((((((0*C*L*I,CLASS1,0x58,
  377.     ((((((0*C*L*I,CLASS1,0x58,
  378.     ((((((0*C*L*V,CLASS1,0xb8,
  379.     ((((((0*C*L*V,CLASS1,0xb8,
  380.     ((((((0*C*M*P,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0xc1,
  381.     ((((((0*C*M*P,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0xc1,
  382.     ((((((0*C*P*X,IMM1|ABS|ZER,0xe0,
  383.     ((((((0*C*P*X,IMM1|ABS|ZER,0xe0,
  384.     ((((((0*C*P*Y,IMM1|ABS|ZER,0xc0,
  385.     ((((((0*C*P*Y,IMM1|ABS|ZER,0xc0,
  386.     ((((((0*D*E*C,ABS|ZER|ZERX|ABSX,0xc2,
  387.     ((((((0*D*E*C,ABS|ZER|ZERX|ABSX,0xc2,
  388.     ((((((0*D*E*X,CLASS1,0xca,
  389.     ((((((0*D*E*X,CLASS1,0xca,
  390.     ((((((0*D*E*Y,CLASS1,0x88,
  391.     ((((((0*D*E*Y,CLASS1,0x88,
  392.     ((((((0*D*F*B,PSEUDO,0,
  393.     ((((((0*D*F*B,PSEUDO,0,
  394.     ((((((0*E*O*R,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x41,
  395.     ((((((0*E*O*R,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x41,
  396.     ((((((0*E*Q*U,PSEUDO,1,
  397.     ((((((0*E*Q*U,PSEUDO,1,
  398.     ((((((0*I*N*C,ABS|ZER|ZERX|ABSX,0xe2,
  399.     ((((((0*I*N*X,CLASS1,0xe8,
  400.     ((((((0*I*N*X,CLASS1,0xe8,
  401.     ((((((0*I*N*Y,CLASS1,0xc8,
  402.     ((((((0*I*N*Y,CLASS1,0xc8,
  403.     ((((((0*J*M*P,ABS|IND,0x40,
  404.     ((((((0*J*M*P,ABS|IND,0x40,
  405.     ((((((0*J*S*R,ABS,0x14,
  406.     ((((((0*L*D*A,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0xa1,
  407.     ((((((0*L*D*A,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0xa1,
  408.     ((((((0*L*D*X,IMM1|ABS|ZER|ABSY2|ZERY,0xa2,
  409.     ((((((0*L*D*X,IMM1|ABS|ZER|ABSY2|ZERY,0xa2,
  410.     ((((((0*L*D*Y,IMM1|ABS|ZER|ABSX|ZERX,0xa0,
  411.     ((((((0*L*D*Y,IMM1|ABS|ZER|ABSX|ZERX,0xa0,
  412.     ((((((0*L*S*R,ABS|ZER|ZERX|ABSX|ACC,0x42,
  413.     ((((((0*M*S*B,PSEUDO,13,
  414.     ((((((0*N*O*P,CLASS1,0xea,
  415.     ((((((0*O*R*A,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x01,
  416.     ((((((0*O*R*G,PSEUDO,3,
  417.     ((((((0*O*R*G,PSEUDO,3,
  418.     ((((((0*P*H*A,CLASS1,0x48,
  419.     ((((((0*P*H*A,CLASS1,0x48,
  420.     ((((((0*P*H*P,CLASS1,0x08,
  421.     ((((((0*P*L*A,CLASS1,0x68,
  422.     ((((((0*P*L*A,CLASS1,0x68,
  423.     ((((((0*P*L*P,CLASS1,0x28,
  424.     ((((((0*P*L*P,CLASS1,0x28,
  425.     ((((((0*R*O*L,ABS|ZER|ZERX|ABSX|ACC,0x22,
  426.     ((((((0*R*O*L,ABS|ZER|ZERX|ABSX|ACC,0x22,
  427.     ((((((0*R*O*R,ABS|ZER|ZERX|ABSX|ACC,0x62,
  428.     ((((((0*R*O*R,ABS|ZER|ZERX|ABSX|ACC,0x62,
  429.     ((((((0*R*T*I,CLASS1,0x40,
  430.     ((((((0*R*T*S,CLASS1,0x60,
  431.     ((((((0*R*T*S,CLASS1,0x60,
  432.     ((((((0*S*B*C,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0xe1,
  433.     ((((((0*S*B*C,IMM2|ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0xe1,
  434.     ((((((0*S*E*C,CLASS1,0x38,
  435.     ((((((0*S*E*D,CLASS1,0xf8,
  436.     ((((((0*S*E*D,CLASS1,0xf8,
  437.     ((((((0*S*E*I,CLASS1,0x78,
  438.     ((((((0*S*E*I,CLASS1,0x78,
  439.     ((((((0*S*T*A,ABS|ZER|INDX|INDY|ZERX|ABSX|ABSY,0x81,
  440.     ((((((0*S*T*X,ABS|ZER|ZERY,0x82,
  441.     ((((((0*S*T*X,ABS|ZER|ZERY,0x82,
  442.     ((((((0*S*T*Y,ABS|ZER|ZERX,0x80,
  443.     ((((((0*T*A*X,CLASS1,0xaa,
  444.     ((((((0*T*A*X,CLASS1,0xaa,
  445.     ((((((0*T*A*Y,CLASS1,0xa8,
  446.     ((((((0*T*S*X,CLASS1,0xba,
  447.     ((((((0*T*S*X,CLASS1,0xba,
  448.     ((((((0*T*X*A,CLASS1,0x8a,
  449.     ((((((0*T*X*A,CLASS1,0x8a,
  450.     ((((((0*T*X*S,CLASS1,0x9a,
  451.     ((((((0*T*X*S,CLASS1,0x9a,
  452.     ((((((0*T*Y*A,CLASS1,0x98,
  453.     ((((((0*T*Y*A,CLASS1,0x98,
  454.     ((((((0*0x20)+(31))*W*O^((((0*R*D,PSEUDO,2,    /* 0x7cab */
  455.     ((((((0*0x20)+(31))*W*O^((((0*R*D,PSEUDO,2,    /* 0x7cab */
  456.     ((((((0*0x20)+(31))*B*Y^((((0*T*E,PSEUDO,0,    /* 0x7edc */
  457.     ((((((0*0x20)+(31))*B*Y^((((0*T*E,PSEUDO,0,    /* 0x7edc */
  458.     ((((((0*0x20)+(31))*D*B^((((0*Y*T,PSEUDO,6,    /* 0x7fb6 */
  459.     ((((((0*0x20)+(31))*N*L^((((0*S*T,PSEUDO,5,    /* 0x7fb8 */
  460.     ((((((0*0x20)+(31))*L*I^((((0*S*T,PSEUDO,4,    /* 0x7ffd */
  461.     0x7fff,0,0,
  462.     0x7fff,0,0,
  463.     0x7fff,0,0,
  464.     0x7fff,0,0
  465. };
  466.  
  467. int    step[] =
  468. {
  469.     3*((OPSIZE+1)/2),
  470.     3*((((OPSIZE+1)/2)+1)/2),
  471.     3*((((((OPSIZE+1)/2)+1)/2)+1)/2),
  472.     3*((((((((OPSIZE+1)/2)+1)/2)+1)/2)+1)/2),
  473.     3*(4),
  474.     3*(3),
  475.     3*(2),
  476.     3*(1),
  477.     0
  478. };
  479. SHAR_EOF
  480. if test -f 'assm1.c'
  481. then
  482.     echo shar: over-writing existing file "'assm1.c'"
  483. fi
  484. cat << \SHAR_EOF > 'assm1.c'
  485. #include "stdio.h"
  486. #include "assm.d1"
  487. #include "assm.d2"
  488.  
  489. #define CPMEOF EOF
  490.  
  491. /*
  492.  *  Two changes to version 1.4 have been made to "port" as6502 to CP/M(tm).
  493.  *  A "tolower()" function call was add to the command line processing
  494.  *  code to (re)map the command line arguments to lower case (CP/M
  495.  *  converts all command line arguments to upper case).  The readline()
  496.  *  function has code added to "ignore" the '\r' character (CP/M includes
  497.  *  the \r character along with \n).
  498.  *
  499.  *  Also, the ability to process multiple files on the command line has been
  500.  *  added.  Now one can do, for example:
  501.  *
  502.  *    as6502 -nisvo header.file source.file data.file ...
  503.  *
  504.  *    George V. Wilder
  505.  *    IX 1A-360 x1937
  506.  *    ihuxp!gvw1
  507.  */
  508.  
  509. main(argc, argv)
  510.    int    argc;
  511.    char *argv[];
  512. {
  513.     char    c;
  514.     int    cnt;
  515.     int    i;
  516.     int    ac;
  517.     char    **av;
  518.  
  519.     while (--argc > 0 && (*++argv)[0] == '-') {
  520.         for (i = 1; (c =  ((*argv)[i])) != '\0'; i++) {
  521.             c |= 0x20 ;  /* make it lower case - tm */
  522.             if (c == 'd')        /* debug flag */
  523.                 dflag++;
  524.             if (c == 'i')        /* ignore .nlst flag */
  525.                 iflag++;
  526.             if (c == 'l')        /* disable listing flag */
  527.                 lflag--;
  528.             if (c == 'n')        /* normal/split address mode */
  529.                 nflag++;
  530.             if (c == 'o')        /* object output flag */
  531.                 oflag++;
  532.             if (c == 's')        /* list symbol table flag */
  533.                 sflag++;
  534.             if (c == 'v')        /* print assembler version */
  535.                 fprintf(stdout, "as6502 - version 4.1b - 11/22/84 - JHV [gvw]\n");
  536.         }
  537.     }
  538.     ac = argc;
  539.     av = argv;
  540.     pass = FIRST_PASS;
  541.     for (i = 0; i < 128; i++)
  542.         hash_tbl[i] = -1;
  543.     errcnt = loccnt = slnum = 0;
  544.     while (pass != DONE) {
  545.         initialize(ac, av, argc);
  546.         if(pass == LAST_PASS && ac == argc)
  547.             errcnt = loccnt = slnum = 0;
  548.         while (readline() != -1)
  549.             assemble();
  550.         if (errcnt != 0) {
  551.             pass = DONE;
  552.             fprintf(stderr, "Terminated with error counter = %d\n", errcnt);
  553.         }
  554.         switch (pass) {
  555.         case FIRST_PASS:
  556.             --ac;
  557.             ++av;
  558.             if(ac == 0) {
  559.                 pass = LAST_PASS;
  560.                 if (lflag == 0)
  561.                     lflag++;
  562.                 ac = argc;
  563.                 av = argv;
  564.             }
  565.             break;
  566.         case LAST_PASS:
  567.             --ac;
  568.             ++av;
  569.             if(ac == 0) {
  570.                 pass = DONE;
  571.                 if (sflag != 0)
  572.                     stprnt();
  573.             }
  574.         }
  575.         wrapup();
  576.         if ((dflag != 0) && (pass == LAST_PASS)) {
  577.             fprintf(stdout, "nxt_free = %d\n", nxt_free);
  578.             cnt = 0;
  579.             for (i = 0; i < 128; i++)
  580.                 if (hash_tbl[i] == -1)
  581.                     cnt++;
  582.             fprintf(stdout, "%d unused hash table pointers out of 128\n", cnt);
  583.         }
  584.     }
  585.     return(0);
  586. }
  587.  
  588. /*****************************************************************************/
  589.  
  590. /* initialize opens files */
  591.  
  592. initialize(ac, av, argc)
  593.    int    ac;
  594.    char *av[];
  595.    int  argc;
  596. {
  597.  
  598.     if (ac == 0) {
  599.         fprintf(stderr, "Invalid argument count (%d).\n", argc);
  600.         exit(1);
  601.     }
  602.     if ((iptr = fopen(*av, "r")) == NULL) {
  603.         fprintf(stderr, "Open error for file '%s'.\n", *av);
  604.         exit(1);
  605.     }
  606.     if ((pass == LAST_PASS) && (oflag != 0) && ac == argc) {
  607.         if ((optr = fopen("6502.out", "w")) == NULL) {
  608.             fprintf(stderr, "Create error for object file 6502.out.\n");
  609.             exit(1);
  610.         }
  611.         else fprintf(optr,"CALL -151"); /* let monitor do loading */
  612.     }
  613. }
  614.  
  615. /* readline reads and formats an input line    */
  616.  
  617. int    field[] =
  618. {
  619.     SFIELD,
  620.     SFIELD + 8,
  621.     SFIELD + 14,
  622.     SFIELD + 23,
  623.     SFIELD + 43,
  624.     SFIELD + 75
  625. };
  626.  
  627. readline()
  628. {
  629.     int    i;        /* pointer into prlnbuf */
  630.     int    j;        /* pointer to current field start    */
  631.     int    ch;        /* current character        */
  632.     int    cmnt;        /* comment line flag    */
  633.     int    spcnt;        /* consecutive space counter    */
  634.     int    string;        /* ASCII string flag    */
  635.     int    temp1;        /* temp used for line number conversion */
  636.  
  637.     temp1 = ++slnum;
  638.     for (i = 0; i < LAST_CH_POS; i++)
  639.         prlnbuf[i] = ' ';
  640.     i = 3;
  641.     while (temp1 != 0) {    /* put source line number into prlnbuf */
  642.         prlnbuf[i--] = temp1 % 10 + '0';
  643.         temp1 /= 10;
  644.     }
  645.     i = SFIELD;
  646.     cmnt = spcnt = string = 0;
  647.     j = 1;
  648.     while ((ch = getc(iptr)) != '\n') {
  649.         if(ch == '\r')
  650.             continue;
  651.         prlnbuf[i++] = ch;
  652.         if ((ch == ' ') && (string == 0)) {
  653.             if (spcnt != 0)
  654.                 --i;
  655.             else if (cmnt == 0) {
  656.                 ++spcnt;
  657.                 if (i < field[j])
  658.                     i = field[j];
  659.                 if (++j > 3) {
  660.                     spcnt = 0;
  661.                     ++cmnt;
  662.                 }
  663.             }
  664.         }
  665.         else if (ch == '\t') {
  666.             prlnbuf[i - 1] = ' ';
  667.             spcnt = 0;
  668.             if (cmnt == 0) {
  669.                 if (i < field[j])
  670.                     i = field[j];
  671.                 if (++j > 3)
  672.                     ++cmnt;
  673.             }
  674.             else i = (i + 8) & 0x78;
  675.         }
  676.         else if ((ch == ';') && (string == 0)) {
  677.             spcnt = 0;
  678.             if (i == SFIELD + 1)
  679.                 ++cmnt;
  680.             else if (prlnbuf[i - 2] != '\'') {
  681.                 ++cmnt;
  682.                 prlnbuf[i-1] = ' ';
  683.                 if (i < field[3])
  684.                     i = field[3];
  685.                 prlnbuf[i++] = ';';
  686.             }
  687.         }
  688.         else if (ch == EOF || ch == CPMEOF)
  689.             return(-1);
  690.         else {
  691.             if ((ch == '"' || ch == '\'' ) && (cmnt == 0))
  692.                 string = string ^ 1;
  693.             spcnt = 0;
  694.             if (i >= LAST_CH_POS - 1)
  695.                 --i;
  696.         }
  697.     }
  698.     prlnbuf[i] = 0;
  699.     return(0);
  700. }
  701.  
  702. /*
  703.  * wrapup() closes the source file
  704.  */
  705.  
  706. wrapup()
  707. {
  708.  
  709.     fclose(iptr);
  710.     if ((pass == DONE) && (oflag != 0)) {
  711.         fputc('\n', optr);
  712.         fclose(optr);
  713.     }
  714.     return;
  715. }
  716.  
  717. /* symbol table print
  718.  */
  719.  
  720. stprnt()
  721. {
  722.     int    i;
  723.     int    j;
  724.     int    k;
  725.  
  726.     fputc('\014', stdout);
  727.     fputc('\n', stdout);
  728.     i = 0;
  729.     while    ((j = symtab[i++]) != 0) {
  730.         for (k = j; k > 0; k--)
  731.             fputc(symtab[i++], stdout);
  732.         for (k = 20 - j; k > 0; k--)
  733.             fputc(' ', stdout);
  734.         ++i;
  735.         j = (symtab[i++] & 0xff);
  736.         j += (symtab[i++] << 8);
  737.         hexcon(4, j);
  738.         fprintf(stdout, "\t%c%c:%c%c\t%c%c%c%c\n",
  739.             hex[3], hex[4], hex[1], hex[2],
  740.             hex[1], hex[2], hex[3], hex[4]);
  741.         i += 2;
  742.     }
  743. }
  744. SHAR_EOF
  745. #    End of shell archive
  746. exit 0
  747.